refactor: use typed errors in eth trace#6829
Conversation
WalkthroughThis PR refactors error handling in the EthTrace struct from untyped Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/rpc/methods/eth/trace/types.rs (1)
1319-1323:⚠️ Potential issue | 🔴 CriticalCritical: Test helper uses incompatible string conversion.
The
errorfield type changed fromOption<String>toOption<TraceError>, but this test helper still uses"ErrForbidden".into(). SinceTraceErrordoesn't implementFrom<&str>orFrom<String>, this code won't compile.🐛 Proposed fix
error: if result_address.is_none() { - Some("ErrForbidden".into()) + Some(TraceError::from_string("ErrForbidden")) } else { None },Or use a more specific variant if appropriate:
error: if result_address.is_none() { - Some("ErrForbidden".into()) + Some(TraceError::ActorError(19)) // ErrForbidden exit code } else { None },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/rpc/methods/eth/trace/types.rs` around lines 1319 - 1323, The test helper is assigning a String into the new error field type Option<TraceError> (using Some("ErrForbidden".into())), which doesn't compile; replace that String conversion with a TraceError value (for example Some(TraceError::ErrForbidden) or, if the enum provides a catch‑all, Some(TraceError::Other("ErrForbidden".into()))), and update the match site around result_address to construct the appropriate TraceError variant; ensure TraceError is in scope (use the TraceError enum name used in this file) so the test helper returns Option<TraceError> instead of Option<String>.
🧹 Nitpick comments (1)
src/rpc/methods/eth/trace/types.rs (1)
74-84: Consider adding a dedicatedUnknownvariant for unrecognized error strings.The current fallback to
ActorError(0)silently loses information when an unrecognized error string is encountered. While this is acceptable for round-tripping internally-produced data, a dedicatedUnknown(String)variant would preserve the original error text and make debugging easier if unexpected strings appear.💡 Optional: Add Unknown variant
pub enum TraceError { // ... existing variants ... /// Actor-level error (catch-all for unrecognised exit codes). #[error("actor error: {}", ExitCode::from(*.0))] ActorError(u32), + /// Unknown error string that couldn't be parsed. + #[error("{0}")] + Unknown(String), }Then in
from_string:} else { - Self::ActorError(0) + Self::Unknown(other.to_string()) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/rpc/methods/eth/trace/types.rs` around lines 74 - 84, The code currently maps unrecognized error strings to ActorError(0); add a new enum variant Unknown(String) to the enum in types.rs and update the from_string function to return Self::Unknown(other.to_string()) in the final else branch (replacing Self::ActorError(0)). Ensure references to the enum (e.g., in from_string, any display/serialize helpers, and places that match on VmError/ActorError) are updated to handle the Unknown(String) variant where appropriate so the original error text is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/rpc/methods/eth/trace/types.rs`:
- Around line 1319-1323: The test helper is assigning a String into the new
error field type Option<TraceError> (using Some("ErrForbidden".into())), which
doesn't compile; replace that String conversion with a TraceError value (for
example Some(TraceError::ErrForbidden) or, if the enum provides a catch‑all,
Some(TraceError::Other("ErrForbidden".into()))), and update the match site
around result_address to construct the appropriate TraceError variant; ensure
TraceError is in scope (use the TraceError enum name used in this file) so the
test helper returns Option<TraceError> instead of Option<String>.
---
Nitpick comments:
In `@src/rpc/methods/eth/trace/types.rs`:
- Around line 74-84: The code currently maps unrecognized error strings to
ActorError(0); add a new enum variant Unknown(String) to the enum in types.rs
and update the from_string function to return Self::Unknown(other.to_string())
in the final else branch (replacing Self::ActorError(0)). Ensure references to
the enum (e.g., in from_string, any display/serialize helpers, and places that
match on VmError/ActorError) are updated to handle the Unknown(String) variant
where appropriate so the original error text is preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c4f73856-c22a-404e-88d6-4f56621ae0dc
📒 Files selected for processing (2)
src/rpc/methods/eth/trace/parity.rssrc/rpc/methods/eth/trace/types.rs
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/rpc/methods/eth/trace/types.rs (1)
49-52: Avoid the extra allocation inSerialize.
serialize_str(&self.to_string())still allocates aStringfor every serialized error.serializer.collect_str(self)writes theDisplayimpl directly and keeps the allocation win from the typed representation.♻️ Proposed fix
impl Serialize for TraceError { fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { - serializer.serialize_str(&self.to_string()) + serializer.collect_str(self) } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/rpc/methods/eth/trace/types.rs` around lines 49 - 52, The Serialize impl for TraceError currently allocates by calling self.to_string(); change the serializer call inside impl Serialize for TraceError (the serialize method) to use serializer.collect_str(self) so the Display impl is written directly without creating an intermediate String; locate the Serialize impl for TraceError and replace the serialize_str(&self.to_string()) usage accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/rpc/methods/eth/trace/types.rs`:
- Around line 63-84: The parser should not coerce unrecognized or malformed
error strings to ActorError(0)/VmError(0); update the enum used by from_string
to either add an Unknown(String) variant (preferred) or make from_string
fallible (Result/Option), then change from_string to return
Unknown(original_input) instead of Self::ActorError(0)/Self::VmError(0) when no
known pattern matches and to propagate parse_exit_code_display failures instead
of defaulting to 0; also add a doc comment to the public from_string explaining
the accepted wire formats and behaviors.
---
Nitpick comments:
In `@src/rpc/methods/eth/trace/types.rs`:
- Around line 49-52: The Serialize impl for TraceError currently allocates by
calling self.to_string(); change the serializer call inside impl Serialize for
TraceError (the serialize method) to use serializer.collect_str(self) so the
Display impl is written directly without creating an intermediate String; locate
the Serialize impl for TraceError and replace the
serialize_str(&self.to_string()) usage accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d7ab684b-20f3-4672-b311-c785b1d205ee
📒 Files selected for processing (2)
src/rpc/methods/eth/trace/parity.rssrc/rpc/methods/eth/trace/types.rs
|
no green checkmark, no review! |
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #6784
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit